<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"  lang="en">
<head>
  <meta charset="UTF-8">
  <script type="text/javascript" th:src="@{/static/js/jquery-1.9.1.min.js}"></script>
  <script type="text/javascript" th:src="@{/static/layui-v2.6.13/layui/layui.js}"></script>
  <link rel="stylesheet" type="text/css" th:href="@{/static/layui-v2.6.13/layui/css/layui.css}"/>
  <title>Goods</title>
  <script>
        function page(p){
            var form = $("#form").serialize();
            window.location.href = "pagegoods?"+form+"&pageNum="+p;
        }
        function rs(){
            window.location.href = "p?rs=1";
        }
        layui.use("layer", function(){
            var layer = layui.layer;
        });

        function openLayer(id){
            layer.open({
              type: 2,
              area: ['650px', '500px'],
              content: 'toupdate?id='+id,
              end: function(){
                  location.reload();
              }
            });
        }
        function openLayer2(){
            layer.open({
              type: 2,
              area: ['650px', '500px'],
              content: 'toinsert',
              end: function(){
                  location.reload();
              }
            });
        }
        function addtype(){
          layer.open({
            type:2,
            area: ['650px','500px'],
            content:'toaddtype',
            end: function(){
              location.reload();
            }
          })
        }
        function checkAll(obj){
          var a = $(obj).prop("checked");
          if(a){
              $(":checkbox[name='xun']").prop("checked",true);
          } else {
              $(":checkbox[name='xun']").prop("checked",false);
          }
        }
        function getAllChecked(){
          var es = $(":checkbox[name='xun']:checked");
          var params = "";
          $.each(es,function(index,item){
                console.info(item.value);
                params += item.value + ",";
          })
          window.location.href="down?ids="+params.substr(0,params.length-1);
        }
    </script>
</head>
<body>

<div class="layui-card">
  <div class="layui-card-header" align="center">查询</div>
  <div class="layui-card-body">
    <form id="form" class="layui-form">
      <div class="layui-form-item layui-inline" style="width: 20%;">
        <input th:if="${obj.name==null}" name="name" type="text" placeholder="请输入商品名" class="layui-btn layui-btn-primary">
        <input th:if="${obj.name!=null}" name="name" type="text" th:value="${obj.name}" placeholder="请输入商品名" class="layui-btn layui-btn-primary">
      </div>
      <div class="layui-form-item layui-inline" style="width: 20%;">
        <select name="type">
          <option value="" >商品类别</option>
          <span  th:each="types:${typelist}">
          <option th:value="${types.type}" th:selected="${obj.type eq types.type}" th:text="${types.name}"></option>
          </span>
        </select>
      </div>
      <div class="layui-form-item layui-inline" style="width: 10%;margin-left: 45px;">
        <button type="button" th:onclick="page([[${pageinfo.pageNum}]])" class="layui-btn layui-btn-primary">查询</button>
      </div>
      <div class="layui-form-item layui-inline" style="width: 10%;margin-left: 45px;">
        <button type="button" th:onclick="openLayer2()" class="layui-btn layui-btn-primary">添加</button>
      </div>
    </form>
  </div>
</div>
<div class="layui-card">
  <div class="layui-card-header" align="center">已上架商品</div>
  <div class="layui-card-body">
    <div align="right">
      <div>
        <button type="button" onclick="getAllChecked()" class="layui-btn layui-btn-primary">下架</button>
        <button type="button" onclick="addtype()" class="layui-btn layui-btn-primary">添加商品类别</button>
      </div>
      <table class="layui-table">
        <tr>
          <th><input type="checkbox" onclick="checkAll(this)"></th>
          <th>id</th>
          <th>名称</th>
          <th>库存</th>
          <th>价格</th>
          <th>类型</th>
          <th>图片</th>
          <th>操作</th>
        </tr>
        <tr th:each="gd:${pageinfo.list}">
          <td><input type="checkbox" th:value="${gd.id}" name="xun"></td>
          <td th:text="${gd.id}" > </td>
          <td th:text="${gd.name}" > </td>
          <td th:text="${gd.amount}" > </td>
          <td th:text="${gd.price}" > </td>
          <td th:text="${gd.type}"></td>
          <td><img th:src="@{/static/img/{url}(url=${gd.url})}" width="30px" height="30px"/></td>
          <td><button type="button" th:onclick="openLayer([[${gd.id}]])" class="layui-btn layui-btn-sm layui-btn-primary">更新</button></td>
        </tr>
      </table >
      <div align="center">
        <button type="button" th:onclick="page(1)" class="layui-btn layui-btn-primary">首页</button>
        <button type="button" th:onclick="page([[${pageinfo.pageNum}-1]])" class="layui-btn layui-btn-primary">上一页</button>
        <span th:text="${pageinfo.pageNum}"></span>
        <span>/</span>
        <span th:text="${pageinfo.pages}"></span>
        <button type="button" th:onclick="page([[${pageinfo.pageNum}+1]])" class="layui-btn layui-btn-primary">下一页</button>
        <button type="button" th:onclick="page([[${pageinfo.pages}]])" class="layui-btn layui-btn-primary">尾页</button>
      </div>
    </div>
  </div>
</div>
</body>
</html>